package com.zhaopin.qa.jmeter.plugins.jsonpathbatchassertion.gui;


import java.awt.BorderLayout;

import org.apache.jmeter.assertions.gui.AbstractAssertionGui;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.testelement.TestElement;

import com.zhaopin.qa.jmeter.plugins.jsonpathbatchassertion.JSONPathBatchAssertion;

public class JSONPathBatchAssertionGui extends AbstractAssertionGui {

	private static final long serialVersionUID = 1L;

	private JsonPathAssetionArgumentsPanel paramPanel;

	public JSONPathBatchAssertionGui() {
		this.init();
	}

	public void init() {
		this.setLayout(new BorderLayout());
		this.setBorder(this.makeBorder());
		this.add(this.makeTitlePanel(), BorderLayout.NORTH);
		if (null == paramPanel) {
			paramPanel = new JsonPathAssetionArgumentsPanel();
			this.add(paramPanel);
		}
	}

	@Override
	public String getLabelResource() {
		return this.getClass().getSimpleName();
	}

	@Override
	public String getStaticLabel() {
		return "JSONPath批量断言";
	}

	@Override
	public void clearGui() {
		super.clearGui();
		paramPanel.clear();
	}

	@Override
	public TestElement createTestElement() {
		JSONPathBatchAssertion jpAssertion = new JSONPathBatchAssertion();
		this.modifyTestElement(jpAssertion);
		return jpAssertion;
	}

	@Override
	public void modifyTestElement(TestElement element) {
		super.configureTestElement(element);
		if (element instanceof JSONPathBatchAssertion) {
			JSONPathBatchAssertion jpAssertion = (JSONPathBatchAssertion) element;
			Arguments args = (Arguments) paramPanel.createTestElement();
			jpAssertion.setJSONPathAssertionArguments(args);
		}
	}

	@Override
	public void configure(TestElement element) {
		super.configure(element);
		if (element instanceof JSONPathBatchAssertion) {
			JSONPathBatchAssertion jpAssertion = (JSONPathBatchAssertion) element;
			Arguments jsonPathAssertionArguments = jpAssertion.getJSONPathAssertionArguments();
			paramPanel.configure(jsonPathAssertionArguments);
		}
	}
}